<style>
    @media screen and (max-width: 500px) {

        .layui-table-view {
            width: 100% !important;
            overflow-x: scroll !important;
            left: 0 !important;
        }

        .layui-table-box {
            width: 1400px !important;
            box-sizing: border-box;
        }

    }
</style>
<div class="layui-form seller-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm return-goods">
                < 返回商品</button> </div> </div> </div> <div class="table-body">
                    <table id="CommentTable"></table>
        </div>

        <script>
            var table, window_box;
            layui.use(['form', 'layedit', 'laydate', 'table', 'layer'], function () {
                var layer = layui.layer;
                table = layui.table.render({
                    elem: '#CommentTable',
                    height: 'full-115',
                    cellMinWidth: '80',
                    page: 'true',
                    limit: '20',
                    url: "{:url('Goods/commentList')}?goods_id={$goods_id}",
                    id: 'CommentTable',
                    response: {
                        statusName: 'status',
                        statusCode: true
                    },
                    cols: [[
                        { type: 'numbers' },
                        { field: 'nickname',  title: '用户', align: 'center', templet: function (data) {
                                if (data.user) {
                                    return data.user.nickname ? data.user.nickname : data.user.mobile;
                                }
                                else {
                                    return data.user_id;
                                }
                            }
                        },
                        { field: 'evaluate', width: 150, sort: true, title: '评价星数', align: 'center', templet: function (data) {
                                // if (data.score == 1) {
                                //     return '好评';
                                // } else if (data.score == 0) {
                                //     return '中评';
                                // } else if (data.score == -1) {
                                //     return '差评';
                                // }
                                return data.score + '星';
                            }
                        },
                        { field: 'content', title: '评价内容', align: 'center' },
                        { field: 'content', title: '评价图片', align: 'center', templet: function (d) {
                                if (d.images_url) {
                                    var html = '';
                                    for (var i = 0; i < d.images_url.length; i++) {
                                        html += '<a href="javascript:void(0);" onclick=viewImage("' + d.images_url[i] + '")><image style="max-width:30px;max-height:30px;" src="' + d.images_url[i] + '"/></a>';
                                    }
                                    return html;
                                } else {
                                    return '';
                                }
                            }
                        },
                        { field: 'order_id', title: '订单号', align: 'center' },
                        { field: 'ctime', sort: true, title: '评价时间', align: 'center' },
                        { field: 'display', sort: true, title: '前台显示', align: 'center', templet: function (data) {
                                if (data.display === 1) {
                                    return '<a href="javascript:void(0);" class="display" data-id="' + data.id + '">隐藏</a>';
                                } else {
                                    return '<a href="javascript:void(0);" class="display" data-id="' + data.id + '">显示</a>';
                                }
                            }
                        },
                        { field: 'operating', title: '操作', align: 'center', templet: function (data) {
                                var html = '';
                                html += '<a class="layui-btn layui-btn-xs comment-return" data-id="' + data.id + '">评价回复</a>';
                                return html;
                            }
                        }
                    ]]
                });

                //前台展示设置
                $(document).on("click", '.display', function () {
                    var id = $(this).attr('data-id');
                    layer.confirm('是否确认该操作？', {
                        title: "提示",
                        btn: ['是', '否']
                    }, function () {
                        JsPost("{:url('Goods/setDisplay')}", { 'id': id }, function (res) {
                            layer.msg(res.msg);
                            layui.table.reload('CommentTable');
                        });
                    }, function () {
                        layer.closeAll();
                    });
                });

                //返回上个页面
                $(document).on("click", '.return-goods', function () {
                    window.history.back();
                });

                //回复
                $(document).on("click", '.comment-return', function () {
                    var id = $(this).attr('data-id');
                    JsPost("{:url('Goods/getCommentInfo')}", { 'id': id }, function (res) {
                        if (res.status) {
                            var seller_content = res.data.seller_content == null ? '' : res.data.seller_content;
                            var score = '';
                            for (var i = 0; i < res.data.score; i++) {
                                score += '<img src="/static/images/redstar.png" width="15" height="15" />';
                            }
                            window_box = layer.open({
                                type: 1,
                                title: "商家回复",
                                area: ['500px', '380px'], //宽高
                                btn: ['保存', '关闭'],
                                content: '<div style="padding:20px"><input type="hidden" id="return-id" value="' + id + '">' +
                                    '<div><span>用户评价：</span>' + res.data.content + '</div>' +
                                    '<div style="margin-top: 15px;"><span>用户评分：</span>' + score + '</div>' +
                                    '<div style="margin-top: 15px;"><span style="display: block;margin-bottom: 15px;">商家回复：</span><textarea class="layui-textarea" name="return-content" id="return-content" cols="10" rows="5">' + seller_content + '</textarea></div></div>',
                                yes: function () {
                                    var id = $("#return-id").val();
                                    var return_content = $("#return-content").val();
                                    JsPost("{:url('Goods/sellerContent')}", { 'id': id, "seller_content": return_content }, function (res) {
                                        layer.closeAll();
                                        layer.msg(res.msg);
                                        layui.table.reload('CommentTable');
                                    });
                                }
                            });
                        } else {
                            layer.msg(res.msg);
                            layui.table.reload('CommentTable');
                        }
                    });
                });
            });
        </script>